
package com.idealighter.game.games.happyfive.handler;

import com.idealighter.game.core.annotation.ResMsgHandler;
import com.idealighter.game.gamehall.dto.MemInfo;
import com.idealighter.game.gamehall.dto.TableInfo;
import com.idealighter.game.games.happyfive.HappyFivePlayer;
import com.idealighter.game.games.happyfive.message.ResEnterRoomMsg;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.robot.common.PlayerPosition;
import com.idealighter.game.robot.core.Player;
import com.idealighter.game.robot.handler.ResMessageHandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@ResMsgHandler(507202)
public class ResEnterRoomHandler implements ResMessageHandler {

  private static final Logger LOG = LoggerFactory.getLogger(ResEnterRoomHandler.class);

  @Override
  public void action(Player player, ResMessage message) {
    ResEnterRoomMsg msg = (ResEnterRoomMsg) message;
    player.position = PlayerPosition.ROOM;
    LOG.info("[欢乐五张]玩家[{}][{}]进入房间[{}]成功", player.userName, player.playerId, player.roomId);
    HappyFivePlayer happyFivePlayer = (HappyFivePlayer) player;
    for (TableInfo table : msg.getTables()) {
      happyFivePlayer.tables.put(table.getId(), table);
    }

    for (MemInfo member : msg.getMembers()) {
      happyFivePlayer.members.put(member.getPlayerId(), member);
    }
    happyFivePlayer.enterTable();
  }
}
